package com.nononsenseapps.feeder.util

import android.content.Context
import android.content.Intent
import android.content.Intent.*
import android.net.Uri
import android.os.Build
import com.nononsenseapps.feeder.core.BuildConfig
import com.nononsenseapps.feeder.core.R

internal fun emailSubject(): String = "Bug report for Feedin"

internal fun emailBody(isTablet: Boolean): String = """
            ${BuildConfig.LIBRARY_PACKAGE_NAME} (flavor Feedin})
            on Android ${Build.VERSION.RELEASE} (SDK-${Build.VERSION.SDK_INT})
            on a Tablet? ${
if (isTablet) {
    "Yes"
} else {
    "No"
}}

            Describe your issue and how to reproduce it below:
        """.trimIndent()

internal fun emailReportAddress(): String = "wushunlian@163.com"

fun emailBugReportIntent(context: Context?): Intent = Intent(ACTION_SENDTO).also {
    it.putExtra(EXTRA_SUBJECT, emailSubject())
    it.putExtra(EXTRA_TEXT, emailBody(context?.resources?.getBoolean(R.bool.isTablet)
            ?: false))
    it.putExtra(EXTRA_EMAIL, emailReportAddress())
    it.data = Uri.parse("mailto:${emailReportAddress()}")
}


fun openGitlabIssues(context: Context?): Intent = Intent(ACTION_VIEW).also {
    it.data = Uri.parse("https://gitee.com/51danju/Feedin/issues")
}
